import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardDome {

    //初始化一副牌
    public static final  String[] Suits={"♠", "♥", "♣", "♦"};
    public static List<Card> buycard(){
        List<Card> cardList = new ArrayList<>();
        for(int i = 0; i < Suits.length; i++) {
            for (int j = 1; j <=13 ; j++) {
                Card card = new Card(j,Suits[i]);
                cardList.add(card);
            }
        }
        return cardList;
    }

    //洗牌
    public static void shuffle(List<Card> cardList){
        for (int i = cardList.size()-1; i > 0 ; i--) {
            Random random = new Random();
            int index = random.nextInt(i);//[0,i)范围
            swap(cardList,i,index);//交换
        }
    }

    public static void swap(List<Card> cardList,int x,int y){
        //交换
        Card tmp = cardList.get(x);
        cardList.set(x,cardList.get(y));
        cardList.set(y,tmp);
    }

    //分牌

    public static void main(String[] args) {
       List<Card> cardList = buycard();
        System.out.println("一副全新的牌");
        System.out.println(cardList);
        System.out.println("洗牌");
        shuffle(cardList);
        System.out.println(cardList);
        System.out.println("分牌");
        List<Card> hand0 = new ArrayList<>();
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<List<Card>> hands = new ArrayList<>();
        hands.add(hand0);
        hands.add(hand1);
        hands.add(hand2);

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = cardList.remove(0);
                hands.get(j).add(card);
            }
        }

        System.out.println("第1个人的牌：");
        System.out.println(hand0);
        System.out.println("第2个人的牌：");
        System.out.println(hand1);
        System.out.println("第3个人的牌：");
        System.out.println(hand2);
        System.out.println("剩下的牌：");
        System.out.println(cardList);



    }

}
